package com.app.service.impl;


import com.app.mapper.ConfigMapper;
import com.app.mapper.ExpertMapper;
import com.app.model.ConfigModel;
import com.app.model.ExpertModel;
import com.app.model.SchoolModel;
import com.app.service.ConfigService;
import com.app.service.ExpertService;
import com.app.util.StringTool;
import com.app.vo.ExpertVo;
import com.app.vo.SchoolVo;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;


/**
 * @Description:专家
 * @Author: N
 * @Date: 2022年11月24日 10点29分
 */
@Service
public class ExpertServiceImpl implements ExpertService {

    @Autowired
    ExpertMapper expertMapper;

    @Override
    public ExpertVo getListByModel(ExpertModel model) {
        QueryWrapper<ExpertModel> queryWrapper = new QueryWrapper<>();

        if (StringTool.isNotEmpty(model.getName())) {
            queryWrapper.like("name", model.getName());
        }
        Page<ExpertModel> pages = new Page<>();
        pages.setCurrent(model.getPage());
        pages.setSize(model.getLimit());
        Page<ExpertModel> page = expertMapper.selectPage(pages, queryWrapper);
        if (page == null) {
            return null;
        } else {
            ExpertVo vo = new ExpertVo();
            vo.setList(page.getRecords());
            vo.setCount((int)page.getTotal());
            return vo;
        }
    }

    @Override
    public ExpertModel getModelById(Integer id) {
        return expertMapper.selectById(id);
    }

    @Override
    public int insert(ExpertModel model) {
        return expertMapper.insert(model);
    }

    @Override
    public void update(ExpertModel model) {
        expertMapper.updateById(model);
    }

    @Override
    public void delete(Integer id) {
        expertMapper.deleteById(id);
    }
}
